﻿using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using System;

namespace xEngine.Rendering.Effects
{
    class PPSplitViewHorizontal
    {
        #region Member Variables

        private SpriteBatch _spriteBatch;

        #endregion

        #region Constructors

        public PPSplitViewHorizontal(SpriteBatch spriteBatch)
        {
            _spriteBatch = spriteBatch;
        }

        #endregion

        #region Functions

        public void SplitViewHorizontal(RenderTarget2D input, RenderTarget2D output, int amount)
        {
            RasterizerState rs = RenderManager.Device.RasterizerState;

            RenderManager.PushRenderTarget(output);

            _spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone);
            _spriteBatch.Draw(input, new Rectangle(0, 0, input.Width, input.Height), Color.White);
            _spriteBatch.Draw(input, new Rectangle(0, 0, input.Width + amount, input.Height), Color.FromNonPremultiplied(255, 255, 255, 64));
            _spriteBatch.Draw(input, new Rectangle(-amount, 0, input.Width + amount, input.Height), Color.FromNonPremultiplied(255, 255, 255, 64));
            _spriteBatch.End();

            RenderManager.PopRenderTarget();

            RenderManager.Device.RasterizerState = rs;
        }

        #endregion
    }
}
